package leetcode.code1870;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int minSpeedOnTime(int[] dist, double hour) {
		int l = 1, r = 10000000;
		int ans = -1;
		while (l <= r) {
			int mid = l + ((r - l) >> 1);
			double cur = 0;
			for (int i = 0; i < dist.length - 1; i++) {
				cur += (dist[i] + mid - 1) / mid;
			}
			cur += 1d * dist[dist.length - 1] / mid;
			if (cur <= hour) {
				ans = mid;
				r = mid - 1;
			} else {
				l = mid + 1;
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(10000000, this.minSpeedOnTime(H.str2array3("[1,1,100000]"), 2.01));
		H.compare(1, this.minSpeedOnTime(H.str2array3("[1,3,2]"), 6));
		H.compare(3, this.minSpeedOnTime(H.str2array3("[1,3,2]"), 2.7));
		H.compare(-1, this.minSpeedOnTime(H.str2array3("[1,3,2]"), 1.9));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
